#!/usr/bin/env python

#THIS FILE IS AUTOMATICALLY GENERATED

from KalAST import *

class KalParenArgList(KalASTNode):
    def parse(self):
        self.require('(')
        self.validators = self.require(KalKeywordArgList)
        self.require(')')


class KalAssignmentStatement(KalASTNode):
    def parse(self):
        self.lvalue = self.require(KalUnaryExpression)
        self.rvalue = self.optional(KalRValue)
        self.eol = self.require(KalEOL)


class KalKeyword(KalASTNode):
    def parse(self):
        self.kw = self.require(KalName)
        self.require('=')
        self.arg = self.require(KalExpression)


class KalKeywordWithComma(KalASTNode):
    def parse(self):
        self.kw = self.require(KalKeyword)
        self.require(',')


class KalArgList(KalASTNode):
    def parse(self):
        self.args1 = self.optional_multiple(KalNameWithComma)
        self.args2 = self.require(KalName)


class KalIfStatement(KalASTNode):
    def parse(self):
        self.require('if')
        self.condition = self.require(KalExpression)
        self.require(':')
        self.eol = self.optional(KalEOL)
        self.true_block = self.optional_multiple(KalStatement)
        self.else_block = self.optional(KalElseBlock)
        self.require('end')
        self.optional('if')
        self.eol = self.require(KalEOL)


class KalModule(KalASTNode):
    def parse(self):
        self.members = self.optional_multiple(KalModuleItem)


class KalForStatement(KalASTNode):
    def parse(self):
        self.require('for')
        self.iterant = self.require(KalName)
        self.require('in')
        self.iterable = self.require(KalExpression)
        self.eol = self.require(KalEOL)
        self.loop_body = self.optional_multiple(KalStatement)
        self.require('next')
        self.iterant_end = self.optional(KalName)
        self.eol = self.require(KalEOL)


class KalRValue(KalASTNode):
    def parse(self):
        self.require('=')
        self.rvalue = self.require(KalExpression)


class KalElseBlock(KalASTNode):
    def parse(self):
        self.require('else')
        self.require(':')
        self.eol = self.optional(KalEOL)
        self.false_block = self.optional_multiple(KalStatement)


class KalTryStatement(KalASTNode):
    def parse(self):
        self.require('try')
        self.require(':')
        self.eol = self.require(KalEOL)
        self.try_block = self.optional_multiple(KalStatement)
        self.handle_block = self.require_multiple(KalHandleBlock)
        self.require('end')
        self.optional('try')
        self.eol = self.require(KalEOL)


class KalClassDefinition(KalASTNode):
    def parse(self):
        self.item = self.require(KalPropertyList,KalMethod,KalFunction,KalStatement)


class KalMapExpression(KalASTNode):
    def parse(self):
        self.require('{')
        self.expr1 = self.optional_multiple(KalMapItemWithComma)
        self.expr2 = self.require(KalMapItem)
        self.require('}')


class KalIntegerExpression(KalASTNode):
    def parse(self):
        self.value = self.require(KalInteger)


class KalBlankStatement(KalASTNode):
    def parse(self):
        self.eol = self.require(KalEOL)


class KalPropertyList(KalASTNode):
    def parse(self):
        self.require('properties')
        self.require(':')
        self.eol = self.require(KalEOL)
        self.item = self.optional_multiple(KalPropertyDefinition)
        self.require('end')
        self.optional('properties')
        self.eol = self.require(KalEOL)


class KalExpressionWithComma(KalASTNode):
    def parse(self):
        self.expr = self.require(KalExpression)
        self.require(',')


class KalParenExpression(KalASTNode):
    def parse(self):
        self.require('(')
        self.expr = self.require(KalExpression)
        self.require(')')


class KalExpression(KalASTNode):
    def parse(self):
        self.lexpr = self.require(KalUnaryExpression)
        self.binexpr = self.optional(KalBinOperand)


class KalClass(KalASTNode):
    def parse(self):
        self.require('class')
        self.name = self.require(KalName)
        self.require('inherits')
        self.parent = self.require(KalName)
        self.require(':')
        self.eol = self.require(KalEOL)
        self.members = self.optional_multiple(KalClassDefinition)
        self.require('end')
        self.optional('class')
        self.eol = self.require(KalEOL)


class KalStringExpression(KalASTNode):
    def parse(self):
        self.value = self.require(KalString)


class KalFloatExpression(KalASTNode):
    def parse(self):
        self.value = self.require(KalFloat)


class KalWhileStatement(KalASTNode):
    def parse(self):
        self.require('while')
        self.condition = self.require(KalExpression)
        self.require(':')
        self.eol = self.require(KalEOL)
        self.loop_body = self.optional_multiple(KalStatement)
        self.require('end')
        self.optional('while')
        self.eol = self.require(KalEOL)


class KalFile(KalASTNode):
    def parse(self):
        self.module = self.require(KalModule)
        self.eof = self.require(KalEOF)


class KalKeywordArgList(KalASTNode):
    def parse(self):
        self.args1 = self.optional_multiple(KalKeywordWithComma)
        self.args2 = self.require(KalKeyword)


class KalReturnStatement(KalASTNode):
    def parse(self):
        self.require('return')
        self.value = self.optional(KalExpression)
        self.eol = self.require(KalEOL)


class KalVargSepecifier(KalASTNode):
    def parse(self):
        self.require('.')
        self.require('.')
        self.require('.')


class KalRaiseStatement(KalASTNode):
    def parse(self):
        self.require('raise')
        self.exception = self.require(KalExpression)
        self.message = self.require(KalExpression)
        self.eol = self.require(KalEOL)


class KalListExpression(KalASTNode):
    def parse(self):
        self.require('[')
        self.expr1 = self.optional_multiple(KalExpressionWithComma)
        self.expr2 = self.require(KalExpression)
        self.require(']')


class KalModuleItem(KalASTNode):
    def parse(self):
        self.item = self.require(KalClass,KalFunction,KalStatement)


class KalMethod(KalASTNode):
    def parse(self):
        self.require('method')
        self.name = self.require(KalName)
        self.require('(')
        self.arguments = self.require(KalArgList,KalVargSepecifier)
        self.require(')')
        self.require(':')
        self.eol = self.require(KalEOL)
        self.statements = self.require(KalStatementBlock)
        self.require('end')
        self.optional('method')
        self.eol = self.require(KalEOL)


class KalUnaryExpression(KalASTNode):
    def parse(self):
        self.expr = self.require(KalFloatExpression,KalIntegerExpression,KalStringExpression,KalNamedExpression,KalParenExpression,KalListExpression,KalMapExpression)


class KalFunction(KalASTNode):
    def parse(self):
        self.require('function')
        self.name = self.require(KalName)
        self.require('(')
        self.arguments = self.optional(KalArgList,KalVargSepecifier)
        self.require(')')
        self.require(':')
        self.eol = self.require(KalEOL)
        self.statements = self.optional_multiple(KalStatement)
        self.require('end')
        self.optional('function')
        self.eol = self.require(KalEOL)


class KalMapItem(KalASTNode):
    def parse(self):
        self.key = self.require(KalExpression)
        self.require(':')
        self.value = self.require(KalExpression)


class KalNameWithComma(KalASTNode):
    def parse(self):
        self.arg = self.require(KalName)
        self.require(',')


class KalStatement(KalASTNode):
    def parse(self):
        self.statement = self.require(KalIfStatement,KalForStatement,KalWhileStatement,KalReturnStatement,KalTryStatement,KalRaiseStatement,KalAssignmentStatement,KalBlankStatement)


class KalHandleBlock(KalASTNode):
    def parse(self):
        self.require('handle')
        self.exception_list = self.require(KalArgList)
        self.require(':')
        self.eol = self.require(KalEOL)
        self.handle_block = self.optional_multiple(KalStatement)


class KalBinOperand(KalASTNode):
    def parse(self):
        self.op = self.require(KalBinOp)
        self.rexpr = self.require(KalExpression)


class KalPropertyDefinition(KalASTNode):
    def parse(self):
        self.type = self.require(KalName)
        self.args = self.optional(KalParenArgList)
        self.name = self.require(KalName)
        self.eol = self.require(KalEOL)


class KalMapItemWithComma(KalASTNode):
    def parse(self):
        self.item = self.require(KalMapItem)
        self.require(',')


class KalNamedExpression(KalASTNode):
    def parse(self):
        self.value = self.require(KalName)
